package com.xtravel.tweet.database.dao;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.table.TableUtils;
import com.xtravel.common.database.helper.DatabaseHelper;
import com.xtravel.tweet.database.po.Advertise;


import java.sql.SQLException;
import java.util.List;

/**
 * Created by Kevin on 2015/10/9.
 */
public class AdvertiseDao {

    private Dao<Advertise, Integer> ope;

    private DatabaseHelper helper;

    public AdvertiseDao(Context context) {
        try {
            helper = DatabaseHelper.getHelper(context);
            ope = helper.getDao(Advertise.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void saveAll(List<Advertise> advertiseList) throws SQLException {
        TableUtils.clearTable(ope.getConnectionSource(), Advertise.class);

        for (Advertise po : advertiseList) {
            ope.create(po);
        }
    }

    public List<Advertise> getAll() throws SQLException {
        return ope.queryForAll();
    }

}
